﻿using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Worktool.CODE_Chris.SQL_DATA;

namespace Worktool.CODE_Chris.DataSourceHelpers
{
    public class ReportRoomsHelper
    {
        private ReportRooms parent;
        private GeneralHelper helper;
        private SQL sql;

        private ReportViewer viewer1;

        private SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter();
        private BindingSource bindingSource1 = new BindingSource();
        private DataTable dataTable1;

        private String select1;
        private String update1;

        public ReportRoomsHelper(ReportViewer viewer1, ReportRooms parent)
        {
            this.parent = parent;
            this.viewer1 = viewer1;
            init();
        }

        private void init()
        {
            sql = new SQL();
            helper = new GeneralHelper();

            populateSQLStrings();
        }

        #region Methoden für viewer1 (Hauptmaske)
        public void getData1()
        {
            try
            {
                //Berichtsdaten erstellen und Pfad angeben
                LocalReport localReport = viewer1.LocalReport;
                localReport.ReportEmbeddedResource = "Worktool.CODE_Chris.Forms.Reporting.RDLCs.Roomcontent.rdlc";

                sqlDataAdapter1 = new SqlDataAdapter(select1, Login.connection);

                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(sqlDataAdapter1);

                //DataTable füllen.
                dataTable1 = new DataTable();
                dataTable1.Locale = System.Globalization.CultureInfo.InvariantCulture;
                sqlDataAdapter1.Fill(dataTable1);
                bindingSource1.DataSource = dataTable1;

                //ReportDataSource erstellen
                ReportDataSource reportDataSource = new ReportDataSource();
                reportDataSource.Name = "Roomcontent";
                reportDataSource.Value = bindingSource1;
                localReport.DataSources.Add(reportDataSource);

                //ReportViewer aktualisieren
                viewer1.RefreshReport();
            }
            catch (Exception e)
            {
                sql.log("FEHLER", e, this.ToString() + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }

        public DataTable getTable1()
        {
            return dataTable1;
        }
        #endregion

        #region SQL-Befehle als Strings
        private void populateSQLStrings()
        {
            select1 = "SELECT Venue, Manufacturer, Model, Description, JLM_Number, Positions_ID, Technische_Ausprägung_1, Technische_Ausprägung_2, Technische_Ausprägung_3 FROM vw_rep_Rooms";
            update1 = "";
        }
        #endregion
    }
}
